cmake_minimum_required(VERSION 3.16)
project(ThunderRaid VERSION 1.0.0 LANGUAGES CXX)

if (MSVC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.29.30129 AND CMAKE_VERSION VERSION_GREATER 3.20.3)
    # this change happened in CMake 3.20.4
    set(CMAKE_CXX_STANDARD 23) # /std:c++latest - unlocks the non stable cpp20 features. For new 16.11 versions
else ()
    set(CMAKE_CXX_STANDARD 20) # /std:c++latest for msvc and -std=c++20 for everyone else.
endif ()

set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

if (MSVC)
    add_compile_options(/utf-8)
    set(WIN32_RC "${CMAKE_BINARY_DIR}/app_win32.rc")
    configure_file("${CMAKE_SOURCE_DIR}/app_win32.rc.in"
            "${WIN32_RC}")

endif ()

find_package(Qt6 COMPONENTS Widgets Multimedia REQUIRED)

file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)

if(MSVC)
    add_executable(ThunderRaid ${source_files} ${WIN32_RC})
else()
    add_executable(ThunderRaid ${source_files})
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Release")
    set_property(TARGET ThunderRaid PROPERTY WIN32_EXECUTABLE true)
endif()
qt_add_binary_resources(resources res/res.qrc OPTIONS -no-compress)
add_dependencies(ThunderRaid resources)
target_link_libraries(ThunderRaid PRIVATE Qt6::Widgets Qt6::Multimedia)
